home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 40 / Amiga Format CD40 (1999-05-11)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-06].iso / -seriously_amiga- / gfxcard / cyberblanker / source-code / main.c < prev    next >
C/C++ Source or Header  |  1999-03-29  |  8KB  |  307 lines

  1.    /***********************************************************************
  2.    *                                                                      *
  3.    *                            COPYRIGHTS                                *
  4.    *                                                                      *
  5.    *   Copyright (c) 1990  Commodore-Amiga, Inc.  All Rights Reserved.    *
  6.    *   This file was modified by © Zinneberg-Soft.                        *
  7.    ***********************************************************************/
  8.  
  9. /*
  10.  * main.c -- Skeleton program for a typical Commodities application.
  11.  */
  12. #include "local.h"
  13. #include "blanker_rev.h"
  14. /*  #include <stdio.h>  */
  15.  
  16.  
  17. #define GETTINGTHERE "burnburnburn"
  18. #define SCREEN_WANTED_WIDTH  1480L
  19. #define SCREEN_WANTED_HEIGHT 7240L
  20.  
  21.  
  22.  
  23.  
  24.  
  25. struct IntuitionBase *IntuitionBase = NULL;
  26. struct Library       *CxBase        = NULL;
  27. struct GfxBase       *GfxBase       = NULL;
  28. struct Library       *GadToolsBase  = NULL;
  29. struct Library       *IconBase      = NULL;
  30. struct Library       *CyberGfxBase  = NULL;
  31. struct Library       *DiskfontBase  = NULL;
  32.  
  33. char     **ttypes;
  34. BOOL windowfirstopening=TRUE;
  35.  
  36. /* these globals are the connection between the main  */
  37. /* program loop and the two message handling routines */
  38.  
  39.  
  40. struct MsgPort *cxport   = NULL; /* commodities messages here      */
  41. ULONG          cxsigflag = 0;    /* signal for above               */
  42.  
  43.  
  44. struct MsgPort *iport    = NULL; /* Intuition IDCMP messages here  */
  45. ULONG          isigflag  = 0;    /* signal for above               */
  46.  
  47. #if CSIGNAL
  48. LONG           csignal   = -1L;
  49. struct Task    *maintask = NULL;
  50. #endif
  51. ULONG          csigflag  = 0L;
  52.  
  53. VOID main(int,char **);
  54. VOID main( argc, argv )
  55. int  argc;
  56. char **argv;
  57. {
  58.  /*   char gettingthere = "burnburnburn";  */
  59.    LONG ktr;
  60.    ULONG    sigrcvd;
  61.    struct   Message    *msg;
  62.    W( char  *str; )
  63.  
  64.    CxBase       =                        OpenLibrary("commodities.library",40L);
  65.    DOSBase      =(struct DosLibrary *)   OpenLibrary("dos.library",40L);
  66.    IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",40L);
  67.    GfxBase      =(struct GfxBase *)      OpenLibrary("graphics.library",40L);
  68.    GadToolsBase =                        OpenLibrary("gadtools.library",40L);
  69.    IconBase     =                        OpenLibrary("icon.library",40L);
  70.    CyberGfxBase =                        OpenLibrary("cybergraphics.library",40L);
  71.    DiskfontBase =                        OpenLibrary("diskfont.library",39L);
  72.  
  73.  
  74.  
  75. if ( ! ( IntuitionBase ) )
  76.    {
  77.  
  78.    ErrorF ("Can't open intuition.library 40L.");
  79.    terminate();
  80.    }
  81.  
  82. if ( ! ( CxBase ) )
  83.    {
  84.  
  85.    ErrorF ("Can't open commodities.library 40L.");
  86.    terminate();
  87.    }
  88.  
  89. if ( ! ( GfxBase ) )
  90.    {
  91.  
  92.    ErrorF ("Can't open graphics.library 40L.");
  93.    terminate();
  94.    }
  95.  
  96. if ( ! ( DOSBase  ) )
  97.    {
  98.  
  99.    ErrorF ("Can't open dos.library 40L.");
  100.    terminate();
  101.    }
  102.  
  103. if ( ! ( GadToolsBase ) )
  104.    {
  105.  
  106.    ErrorF ("Can't open gadtools.library 40L.");
  107.    terminate();
  108.    }
  109.  
  110. if ( ! ( IconBase ) )
  111.    {
  112.  
  113.    ErrorF ("Can't open icon.library 40L.");
  114.    terminate();
  115.    }
  116.  
  117. if ( ! ( CyberGfxBase ) )
  118.    {
  119.  
  120.    ErrorF ("Can't open cybergraphics.library 40L.");
  121.    terminate();
  122.    }
  123.  
  124. if ( ! ( DiskfontBase ) )
  125.    {
  126.  
  127.    ErrorF ("Can't open diskfont.library 39L.");
  128.    terminate();
  129.    }
  130.  
  131. #if CSIGNAL
  132.    if((csignal = AllocSignal(-1L))==-1)
  133.    {
  134.       D1( kprintf("main.c: main() Failed to get custom signal\n") );
  135.       terminate();
  136.    }
  137.    csigflag = 1L <<csignal;
  138.    maintask=FindTask(0L);
  139. #endif
  140.  
  141.    /* commodities support library function to find argv or tooltypes   */
  142.    ttypes = ArgArrayInit( argc, argv );
  143.  
  144.              for ( ktr = 0; ktr < argc; ktr++)
  145.                {
  146.                  if (stricmp(argv[1],"?")==0)
  147.                   {
  148.                    ErrorF ("%s",TEMPLATE);
  149.                    terminate();
  150.                   }
  151.  
  152.                  if (stricmp(argv[ktr],"seconds")==0)
  153.                   {
  154.                   ErrorF ("Incorrect Arguments: " "%s %s",VSTRING,TEMPLATE);
  155.                   terminate();
  156.                   }
  157.  
  158.                  if (stricmp(argv[ktr],"?")==0)
  159.                   {
  160.                    ErrorF ("Incorrect Arguments: " "%s %s",VSTRING,TEMPLATE);
  161.                    terminate();
  162.                   }
  163.                }
  164.  
  165.  
  166.    /**********************************/
  167.  
  168.    D1(
  169.       {
  170.          int xx=0;
  171.  
  172.          while(ttypes[xx])
  173.          {
  174.             printf("ttypes[0x%lx]=%s\n",xx,ttypes[xx]);
  175.             xx++;
  176.          }
  177.       }
  178.    )
  179.  
  180.    if ( ! setupCX( ttypes ) )
  181.    {
  182.       D1( kprintf("main.c: main() setupCX failed\n") );
  183.       terminate();
  184.    }
  185.    W(
  186.       str = ArgString( ttypes, POP_ON_START_TOOL_TYPE,CX_DEFAULT_POP_ON_START);
  187.       if(strcmpi(str,"yes")==0)
  188.          setupWindow();         /* will try to setup iport      */
  189.       D1( kprintf("main.c: main() After setupWindow\n") );
  190.    )
  191.  
  192.    for (;;)            /* exit by calling terminate   */
  193.    {
  194.       /* handling two ports:
  195.        * either will wake us up;
  196.        * simple approach often works.
  197.        */
  198.       D1( kprintf("main.c: main() Waiting for a signal\n") );
  199.       sigrcvd = Wait ( SIGBREAKF_CTRL_C | isigflag | cxsigflag | csigflag );
  200.       D1( kprintf("main.c: main() Recieved a signal\n") );
  201.  
  202.       /* commodities convention: easy to kill   */
  203.       if ( sigrcvd & SIGBREAKF_CTRL_C )
  204.       {
  205.          D1( kprintf("main.c: main() Recieved a SIGBREAKF_CTRL_C\n") );
  206.          terminate();
  207.       }
  208.  
  209. #if CSIGNAL
  210.       if ( sigrcvd & csigflag )
  211.       {
  212.          D1( kprintf("main.c: main() Recieved a Custom Signal\n") );
  213.          handleCustomSignal();
  214.       }
  215. #endif
  216.  
  217.       while(cxport && (msg=GetMsg(cxport)))
  218.          handleCxMsg(msg);
  219.       W(
  220.          while(iport && (msg=(struct Message *)GT_GetIMsg(iport)))
  221.             handleIMsg((struct IntuiMessage *)msg);
  222.       )
  223.    }
  224.  
  225. }
  226. /****i* Blank.ld/terminate() ******************************************
  227. *
  228. *   NAME
  229. *        terminate -- Cleanup all resources and exit the program.
  230. *
  231. *   SYNOPSIS
  232. *        terminate()
  233. *
  234. *        VOID terminate(VOID);
  235. *
  236. *   FUNCTION
  237. *        This function performs all the necessary cleanup for the
  238. *        commodity and calls exit() to return control to the OS.
  239. *        No matter how the program exits this should be the last function
  240. *        called.
  241. *
  242. *   INPUTS
  243. *        None.
  244. *
  245. *   RESULT
  246. *        All resources are freed and the program exits.
  247. *
  248. *   EXAMPLE
  249. *        if(!AllocWindow())
  250. *           terminate();
  251. *
  252. *   NOTES
  253. *        This function must be set up so that it can be called at any
  254. *        time regardless of the current state of the program.
  255. *
  256. *   BUGS
  257. *
  258. *   SEE ALSO
  259. *        shutdownCX();
  260. *        shutdownWindow();
  261. *
  262. *****************************************************************************
  263. *
  264. */
  265. VOID terminate()
  266. {
  267.    D1( kprintf("main.c: terminate() enter\n") );
  268.  
  269.    shutdownCX();
  270.    D1( kprintf("main.c: terminate(), after shutdownCX()\n") );
  271.  
  272.    W(
  273.       shutdownWindow();
  274.       D1( kprintf("main.c: terminate(), after shutdownWindow()\n") );
  275.    )
  276.  
  277.    ArgArrayDone();    /* cx_supp.lib function   */
  278.    D1( kprintf("main.c: terminate(), after ArgArrayDone()\n") );
  279.  
  280. #if CSIGNAL
  281.    if(csignal != -1) FreeSignal(csignal);
  282.    D1( kprintf("main.c: terminate(), after FreeSignal()()\n") );
  283. #endif
  284.  
  285.    D1( kprintf("main.c: terminate() CxBase        = %lx\n",CxBase) );
  286.    D1( kprintf("main.c: terminate() IntuitionBase = %lx\n",IntuitionBase) );
  287.    D1( kprintf("main.c: terminate() GfxBase       = %lx\n",GfxBase) );
  288.    D1( kprintf("main.c: terminate() DOSBase       = %lx\n",DOSBase) );
  289.    D1( kprintf("main.c: terminate() GadToolsBase  = %lx\n",GadToolsBase) );
  290.    D1( kprintf("main.c: terminate() IconBase      = %lx\n",IconBase) );
  291.    D1( kprintf("main.c: terminate() CyberGfxBase  = %lx\n",CyberGfxBase) );
  292.    D1( kprintf("main.c: terminate() DiskfontBase  = %lx\n",DiskfontBase) );
  293.  
  294.    if(CxBase)        CloseLibrary(CxBase);
  295.    if(IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
  296.    if(GfxBase)       CloseLibrary((struct Library *)GfxBase);
  297.    if(DOSBase)       CloseLibrary((struct Library *)DOSBase);
  298.    if(GadToolsBase)  CloseLibrary(GadToolsBase);
  299.    if(IconBase)      CloseLibrary(IconBase);
  300.    if(CyberGfxBase)  CloseLibrary((struct Library *)CyberGfxBase);
  301.    if (DiskfontBase) CloseLibrary((struct Library *)DiskfontBase);
  302.    D1( kprintf("main.c: terminate(), after CloseLibrarys()\n") );
  303.  
  304.    exit(0);
  305. }
  306.  
  307.